home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / SPLIT_P.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  3KB  |  107 lines

  1. /*  SPLIT_P.C
  2.  *  demonstrates split_path(), normalize_path()
  3.  *  and make_path()
  4.  *  last mod.: 28-AUG-91
  5.  */
  6.  
  7. #include <STDIO.H>
  8. #include <STDLIB.H>
  9.  
  10. #include <L_DIR.H>
  11. #include <L_STR.H>
  12.  
  13. Uchar path[_MAX_PATH_];
  14. Uchar drive[_MAX_DRIVE_];
  15. Uchar dir[_MAX_DIR_];
  16. Uchar file[_MAX_FILE_];
  17. Uchar ext[_MAX_EXT_];
  18. Uchar normal_path[_MAX_PATH_];
  19.  
  20. /*-----------*/
  21. void main(void)
  22. {
  23. int result;
  24.  
  25. while ( TRUE )
  26.     {
  27.     puts("\nEnter path to be split into its components:");
  28.     gets_n(path,_MAX_PATH_ - 4);
  29.     if ( !*trim(path) )
  30.         exit(0);
  31.     putchar('\n');
  32.     result = split_path(path,drive,dir,file,ext);
  33.     if ( result < 0 )
  34.         {
  35.         switch ( result )
  36.             {
  37.             case -1:
  38.                 printf("Invalid path.\n");
  39.                 break;
  40.             case -2:
  41.                 printf("Invalid drive in path.\n");
  42.                 break;
  43.             case -3:
  44.                 printf("Disk not present in drive specified in path.\n");
  45.                 break;
  46.             case -4:
  47.                 printf("Path is NULL or empty.\n");
  48.                 break;
  49.             case -6:
  50.                 printf("Path is too long.\n");
  51.                 break;
  52.             case -8:
  53.                 printf("Normalized path is too long.\n");
  54.                 break;
  55.             case -9:
  56.                 printf("Name exceeds 12 characters.\n");
  57.                 break;
  58.             case -10:
  59.                 printf("Extension exceeds 3 characters.\n");
  60.                 break;
  61.             case -11:
  62.                 printf("Base exceeds 8 characters.\n");
  63.                 break;
  64.             case -12:
  65.                 printf("Base is of zero length.\n");
  66.                 break;
  67.             default:
  68.                 printf("Unknown error.\n");
  69.             }
  70.         }
  71.     else
  72.         {
  73.         result = normalize_path(path,normal_path);
  74.         printf("Normalized path:\n%s\n",normal_path);
  75.         printf("Drive ");
  76.         if ( *drive )
  77.             printf("= %s\n",drive);
  78.         else
  79.             printf("not specified.\n");
  80.         printf("Directory ");
  81.         if ( *dir )
  82.             printf("= %s\n",dir);
  83.         else
  84.             printf("not specified.\n");
  85.         printf("Filename ");
  86.         if ( *file )
  87.             printf("= %s\n",file);
  88.         else
  89.             printf("not specified.\n");
  90.         printf("Extension ");
  91.         if ( *ext )
  92.             printf("= %s\n",ext);
  93.         else
  94.             printf("not specified.\n");
  95.         printf("Path or file %s.\n",
  96.             ( result & _PATH_EXISTS_ ?
  97.              "exists" : "does not exist" ) );
  98.         /*  now make the path again  */
  99.         result = make_path(path,drive,dir,file);
  100.         if ( result >= 0 )
  101.             printf("Path remade:\n%s\n",path);
  102.         else
  103.             printf("Error %d when remaking path.\n",result);
  104.         }
  105.     }
  106. }
  107.